package cn.itcast.mq.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MQ配置类
 *
 * @Author mr.yi
 * @Date 2025/1/5 11:17
 */
@Configuration
public class RabbitConfig {

    /**
     * 创建队列
     * @return
     */
    @Bean
    public Queue simple(){
        return new Queue("simple.queue",true);
    }

    @Bean
    public Queue work(){
        return new Queue("work.queue",true);
    }

    @Bean
    public Queue fanout1(){
        return new Queue("fanout.queue1");
    }

    /**
     * 创建队列
     * @return
     */
    @Bean
    public Queue fanout2(){
        return new Queue("fanout.queue2");
    }

    /**
     * 创建交换机
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("itcast.fanout");
    }
    /**
     * 声明广播交换机和队列的绑定关系
     * @param fanout1
     * @param fanoutExchange
     * @return
     */
    @Bean
    public Binding bindFanoutQueue1(Queue fanout1, FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanout1).to(fanoutExchange);
    }
    /**
     * 声明广播交换机和队列的绑定关系
     * @param fanout2
     * @param fanoutExchange
     * @return
     */
    @Bean
    public Binding bindFanoutQueue2(Queue fanout2, FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanout2).to(fanoutExchange);
    }


}
